<?php

namespace Xin\VerifyCode\Laravel;

use Illuminate\Support\ServiceProvider;
use Xin\VerifyCode\Contracts\Factory as VerifyCodeFactory;
use Xin\VerifyCode\VerifyCodeManager;

class VerifyCodeServiceProvider extends ServiceProvider
{
	/**
	 * Register any application services.
	 *
	 * @return void
	 */
	public function register()
	{
		$this->registerManager();

		$this->registerCommands();

		$this->mergeConfigFrom(__DIR__ . '/../../config/config.php', 'verify_code');
	}

	/**
	 * Booting the package.
	 */
	public function boot()
	{
		$this->registerConfig();
	}

	/**
	 * 注册管理器
	 * @return void
	 */
	protected function registerManager()
	{
		$this->app->singleton(VerifyCodeManager::class, function () {
			$manager = new VerifyCodeManager(
				$this->app['config']->get('verify_code'),
			);

			$this->registerDrivers($manager);

			return $manager;
		});
		$this->app->alias(VerifyCodeManager::class, 'verify_code');
		$this->app->alias(VerifyCodeManager::class, VerifyCodeFactory::class);

		$this->app->singleton('verify_code.channel', function ($app) {
			return $app['verify_code']->channel();
		});
	}

	/**
	 * 注册驱动
	 */
	protected function registerDrivers(VerifyCodeManager $manager)
	{

	}

	protected function registerCommands()
	{
		$this->commands([
		]);
	}

	/**
	 * 注册配置
	 * @return void
	 */
	protected function registerConfig()
	{
		$configPath = __DIR__ . '/../../config/config.php';
		$this->publishes([
			$configPath => config_path('verify_code.php'),
		], 'config');
	}
}
